<%--
    Document   : gsearchresults
    Created on : Nov 16, 2010, 12:37:34 PM
    Author     : bertram
--%>

<%@page import="java.util.Map"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="css/main.css" rel="stylesheet" type="text/css" />
        <script type='text/javascript' src='jquery.js'></script>

        <script type="text/JavaScript">
            $(document).ready(function(){
                $('#messageparagraph').click(function(event) {
                    id = event.target.toString().split("#")[1];
                    top.updateByKid(id);
                    top.closeFancyBox();
                });

                $("form#searchbox").submit(function(){
                    $.ajax({
                        url: 'gsearch.do',//?searchterm='+$("#gSearchTerm").val(),
                        type: 'POST',
                        dataType: 'json',
                        timeout: 300000,
                        data: "searchterm="+$("#gSearchTerm").val(),
                        error: function(text){

                            alert('fejl' + text);
                        },
                        success: function(json){

                            showresults(json);
                        }
                    });

                    return false;
                });
            });
            function showresults(json) {
                
                

                if(json.status == 2) alert("ingen resultater");//$("#messageparagraph").append("ingen resultater");
                else{
                    
                    var worklist = json.works;
                    $.each(worklist, function() {
                        
                        $("#messageparagraph").append("<a href='#"+this.reginID+"'>" + this.title + "</a><br />");
                        $("#messageparagraph").append("Kunstner:")
                        var artistlist = this.kunstnere;
                        $.each(artistlist, function(index, value){
                            $("#messageparagraph").append(value.name + "<br />");
                        });
                        
                    });
                }
            }
            function sendSearch(term){
                $.ajax({
                    url: 'gsearch.do',//?searchterm='+$("#gSearchTerm").val(),
                    type: 'POST',
                    dataType: 'json',
                    timeout: 30000,
                    data: "searchterm="+term,
                    error: function(text){
                        alert('Error loading JSON');
                    },
                    success: function(xml){
                        showresults(xml);
                    }
                });
            }
        </script>



        <title>Søgning</title>
    </head>
    <%Map params = request.getParameterMap();
                System.out.println("mappppp");
    %>
    <body>
        Her kan du søge efter værker der allerede er registreret i kunstindeks danmark
        og hente informationerne derfra. Vi anbefaler at du søger ved at angive titlen
        eller en del af titlen på værket og trykker "søg".
        <form name="kidsearchbox" action="gsearchresults.jsp" method="POST" id="searchbox">
            <input type="text" name="gSearchTerm" size="10" id="gSearchTerm">
            <input type="submit" value="Søg" name="btn" id="btn"/>
        </form>
        <div id="results">
            <p id="messageparagraph">
                <span id="loading"></span>
            </p>
        </div>

    </body>
</html>
